package com.ycc.biz.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycc.biz.common.PageResult;
import com.ycc.biz.pojo.entity.BizBuyer;
import com.ycc.biz.mapper.BizBuyerMapper;
import com.ycc.biz.pojo.entity.SysUser;
import com.ycc.biz.pojo.query.BizBuyerQuery;
import com.ycc.biz.pojo.vo.BizBuyerVO;
import com.ycc.biz.service.BizAttachmentService;
import com.ycc.biz.service.BizBuyerService;
import com.ycc.biz.service.SysUserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* @author 吴彦良
* @description 针对表【biz_buyer(买家表)】的数据库操作Service实现
* @createDate 2025-03-07 14:49:22
*/
@Service
@AllArgsConstructor
public class BizBuyerServiceImpl extends ServiceImpl<BizBuyerMapper, BizBuyer> implements BizBuyerService {

    private final SysUserService sysUserService;

    @Override
    public Boolean addBuyer(BizBuyer buyer, HttpServletRequest request) {
        SysUser loginUser = sysUserService.getLoginUser(request);
        String id = loginUser.getId();
        buyer.setUserId(id);
        this.save(buyer);
        return true;
    }

    @Override
    public PageResult<BizBuyerVO> pageBuyers(BizBuyerQuery query) {
        // 创建分页对象
        Page<BizBuyerVO> page = query.buildPage();
        
        // 调用自定义分页查询
        Page<BizBuyerVO> resultPage = getBaseMapper().selectBuyerPage(page, query);
        
        // 转换为分页响应
        return PageResult.build(resultPage);
    }
}




